local skel = fk.CreateSkill {
  name = "emo__shenwei",
  tags = {Skill.Compulsory},
}

skel:addEffect(fk.TurnStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    if target == player and #player:getEquipments(Card.SubtypeWeapon) == 0 and #player:getAvailableEquipSlots(Card.SubtypeWeapon) > 0 then
      local sword = player:getMark(skel.name)
      return sword == 0 or player.room:getCardArea(sword)== Card.Void
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local sword = player:getMark(skel.name)
    if sword == 0 then
      sword = room:printCard("kunwu_sword", Card.Spade, 2).id
      room:setPlayerMark(player, skel.name, sword)
      room:setCardMark(Fk:getCardById(sword), MarkEnum.DestructOutMyEquip, 1)
    end
    room:moveCardTo(sword, Card.PlayerEquip, player, fk.ReasonJustMove, skel.name, nil, true, player)
  end,
})

skel:addEffect(fk.Damage, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    return target == player and data.card and data.card.trueName == "slash" and not data.to:isNude()
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#emo__shenwei-invoke:"..data.to.id}) then
      event:setCostData(self, {tos = {data.to}})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = data.to:getCardIds("he")
    local moves = {}
    local rat = 0.85 -- 击飞到手牌里的概率
    local others = room:getOtherPlayers(data.to, false)
    for _, cardId in ipairs(cards) do
      local to
      if #others > 0 and math.random() < rat then
        to = table.random(others)
      end
      local moveFound = table.find(moves, function(move)
        return move.to == to
      end)
      if moveFound then
        table.insert(moveFound.ids, cardId)
      else
        table.insert(moves, {
          ids = { cardId },
          from = data.to,
          to = to,
          toArea = to and Card.PlayerHand or Card.DiscardPile,
          moveReason = to and fk.ReasonPrey or fk.ReasonPutIntoDiscardPile,
          skillName = skel.name,
          moveVisible = true,
          proposer = to and to or player,
        })
      end
    end
    room:moveCards(table.unpack(moves))
  end,
})

Fk:loadTranslationTable{
  ["emo__shenwei"] = "神威",
  [":emo__shenwei"] = "锁定技，回合开始时，若你未装备武器，将一张♠2【锟铻剑】置入装备区（离开装备区销毁）。每当你使用【杀】造成伤害后，你可以将受伤角色的所有牌轰散（随机移动至弃牌堆或其他角色手牌中）。",
  ["#emo__shenwei-invoke"] = "神威：你可以将 %src 的所有牌轰散！",

  ["$emo__shenwei1"] = "剑锁青霄，怒起雷霆!",
  ["$emo__shenwei2"] = "清源妙道，显圣威灵!",
}


return skel
